<?php
class EventNotifier extends CComponent
{
 private static $event_notifier;
 public $params;
 
 public static function setup()
 {
		if (!isset(self::$event_notifier)) {
            $c = __CLASS__;
            self::$event_notifier = new $c;
       
		self::$event_notifier->onRegister = array(new EmailComponent, 'emailHandler');
		self::$event_notifier->onForgotPassword = array(new EmailComponent, 'emailHandler');
		self::$event_notifier->onChangePassword = array(new EmailComponent, 'emailHandler');
		self::$event_notifier->onOrderPlaced = array(new EmailComponent, 'emailHandler');
		self::$event_notifier->onOrderPlacedCustomer = array(new EmailComponent, 'emailHandler');
		self::$event_notifier->onCustomerRegistration = array(new EmailComponent, 'emailHandler');
		self::$event_notifier->onOrderForwarded = array(new EmailComponent, 'emailHandler');
		}
    return self::$event_notifier;
		    
 }		

  public function onRegister($event)
  {
    $this->raiseEvent('onRegister', $event);
  }
  
  public function onForgotPassword($event)
  {
    $this->raiseEvent('onForgotPassword', $event);
  }
  
  public function onChangePassword($event)
  {
    $this->raiseEvent('onChangePassword', $event);
  }

  public function onOrderPlaced($event)
  {
  	$this->raiseEvent('onOrderPlaced', $event);
  }

  public function onOrderPlacedCustomer($event)
  {
  	$this->raiseEvent('onOrderPlacedCustomer', $event);
  }
  
  public function onCustomerRegistration($event)
  {
  	$this->raiseEvent('onCustomerRegistration', $event);
  }
  
    public function onOrderForwarded($event)
  {
  	$this->raiseEvent('onOrderForwarded', $event);
  }

  public function register($user_object)
  {
  	$obj_event = new CEvent($this);
  	$param_array['email_slug'] = 'registration';
  	$param_array['object'] = $user_object;
  	$obj_event->params = $param_array;
  	$this->onRegister($obj_event);   
  }
  
  public function forgotPassword($user_object)
  {
  	$obj_event = new CEvent($this);
  	$param_array['email_slug'] = 'forgot_password';
  	$param_array['object'] = $user_object;
  	$obj_event->params = $param_array;
  	$this->onForgotPassword($obj_event);  
  }
  
  public function changePassword($user_object)
  {
  	$obj_event = new CEvent($this);
  	$param_array['email_slug'] = 'change_password';
  	$param_array['object'] = $user_object;
  	$obj_event->params = $param_array;
  	$this->onChangePassword($obj_event);    		
  }
   
  public function orderplaced($order_object)
  {
  	$obj_event = new CEvent($this);
  	$param_array['email_slug'] = 'order_placed';
  	$param_array['object'] = $order_object;
  	$obj_event->params = $param_array;
  	$this->onOrderPlaced($obj_event);    		
  }

  public function orderplaced_customer($order_object)
  {
  	$obj_event = new CEvent($this);
  	$param_array['email_slug'] = 'orderplaced_customer';
  //	$param_array['email_id'] = $emailid;
  	$param_array['object'] = $order_object;
  	$obj_event->params = $param_array;
  	$this->onOrderPlacedCustomer($obj_event);    		
  }
  
  public function customer_registration($order_object)
  {
  	$obj_event = new CEvent($this);
  	$param_array['email_slug'] = 'customer_registration';
  	$param_array['object'] = $order_object;
  	$obj_event->params = $param_array;
  	$this->onCustomerRegistration($obj_event);    		
  }
  
    public function order_forwarded($order_object)
  {
  	$obj_event = new CEvent($this);
  	$param_array['email_slug'] = 'forwarded';
  	$param_array['object'] = $order_object;
  	$obj_event->params = $param_array;
  	$this->onOrderForwarded($obj_event);    		
  }
}